package com.houtai.controller.user.info;


import com.houtai.authority.Authority;
import com.houtai.authority.AuthorityType;
import com.houtai.base.RetInfo;
import com.houtai.bean.TdUserInfo;
import com.houtai.bean.TsJzAdmin;
import com.houtai.bean.dto.user.info.TdUserInfoListDto;
import com.houtai.service.funcion.FuncionService;
import com.houtai.service.user.info.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by lizhun on 2017/7/19.
 */
@Controller
@RequestMapping(value = {"v5"})
public class UserInfoController {
    @Resource
    private UserInfoService userInfoService;
    @Autowired
    private RedisTemplate redisTemplate;
    @Resource
    private FuncionService funcionService;

    /**
     * @Purpose  分页加载个人信息
     * @version  1.0
     * @author   lizhun
     * @param    request
     * @return   RetInfo
     */
    @RequestMapping(value="/user/info/list")
    @Authority(AuthorityType.Login)
    public ModelAndView list(HttpServletRequest request, TdUserInfoListDto page){
        ModelAndView mv = new ModelAndView("user/info/list");
        TsJzAdmin tsJzAdmin = (TsJzAdmin) redisTemplate.opsForValue().get(request.getParameter("token")) ;
        mv.addObject("retInfo", userInfoService.userInfoList(page, request));
        mv.addObject("token", request.getParameter("token"));
        mv.addObject("father_id", request.getParameter("father_id"));
        mv.addObject("funcions", funcionService.findSonFuncion(tsJzAdmin, Integer.valueOf(request.getParameter("father_id"))));
        return mv;
    }


    /**
     * @Purpose   审核个人信息
     * @param     tdUserInfo
     * @version   1.0
     * @author    李准
     * @time      2017-08-19
     * @return    RetInfo
     */
    @RequestMapping(value = "/user/info/update/state", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    @Authority(AuthorityType.Login)
    public RetInfo valid(TdUserInfo tdUserInfo, HttpServletRequest request) {

        return userInfoService.auditTdUserInfo(tdUserInfo, request);
    }
}
